package com.ty.admin.controller;

import java.util.Arrays;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.ty.skysystem.entity.RoleEntity;
import com.ty.skysystem.service.RoleService;
import com.ty.common.utils.PageUtils;
import com.ty.common.utils.R;

/**
 * 系统角色表: 用于存放系统权限数据，管理用户权限
 *
 * @author tianyuzhu
 * @email 1659770218@QQ.COM
 * @date 2020-12-11 16:02:37
 */
@RestController
@RequestMapping("role")
public class RoleController {
  @Autowired private RoleService roleService;

  /** 列表 */
  @RequestMapping("/list")
  public R list(@RequestParam Map<String, Object> params) {
    PageUtils page = roleService.queryPage(params);

    return R.ok().put(page);
  }

  /** 信息 */
  @RequestMapping("/info/{roleId}")
  public R info(@PathVariable("roleId") Long roleId) {
    RoleEntity role = roleService.getById(roleId);

    return R.ok().put(role);
  }

  /** 保存 */
  @RequestMapping("/save")
  public R save(@RequestBody RoleEntity role) {
    roleService.save(role);

    return R.ok();
  }

  /** 修改 */
  @RequestMapping("/update")
  public R update(@RequestBody RoleEntity role) {
    roleService.updateById(role);

    return R.ok();
  }

  /** 删除 */
  @RequestMapping("/delete")
  public R delete(@RequestBody Long[] roleIds) {
    roleService.removeByIds(Arrays.asList(roleIds));

    return R.ok();
  }
}
